package com.handpay.zztong.hp.smartpay;



import com.handpay.framework.MD5;
import com.handpay.zztong.hp.protocol.BaseProtocolKey;

import java.util.Map;

/**
 * Created by sxshi on 2017-12-5.
 */

public class SignUtil {

    public static final String VERSION = "1";

    private static String paramToString(Map<String, String> params) {
        if (params.isEmpty())
            return VERSION;
        return VERSION + params.get(BaseProtocolKey.REAL_NAME) + params.get(BaseProtocolKey.PHONE) + params.get(BaseProtocolKey.ID_CODE) + params.get(BaseProtocolKey.CHANNEL_CODE) + params.get(BaseProtocolKey.MER_AGENT_CODE);
    }

    /**
     * 获取MD5签名
     *
     * @param params
     * @param key
     * @return
     */
    public static String getSignVeryfy(Map<String, String> params, String key) {
        if (!params.isEmpty()) {
                String paramString = paramToString(params);
                String sign = MD5.toMD5(paramString).toLowerCase();
                return sign;
        } else {
            return null;
        }
    }
}
